#ifndef ST_WAITER_THREAD_H_INCLUDED
#define ST_WAITER_THREAD_H_INCLUDED

#include "thread.h"
#include "sys_socket.h"
#include <list>
using std::list;

class STSockHolder;

class STWaiterThread: public Thread
{
public:
    STWaiterThread();
    virtual ~STWaiterThread();

    virtual void run();
    virtual void stop();
    bool addSockHolder(STSockHolder* sockHolder);
    bool removeSockHolder(STSockHolder* sockHolder);
    virtual bool handleMsg();
    void sendMsg(const void* msg, unsigned int msgLen);
private:
    enum { MAX_NUM_SOCKS = 62 };
    void rebuildFdSet();
    bool removeSockHolder_unlocked(STSockHolder* sockHolder);

    list<STSockHolder*> m_sockHolders;
    int m_msgSock;
    int m_maxFd;
    sockaddr_in m_msgSockAddr;
    fd_set m_fdset;
};

#endif // ST_WAITER_THREAD_H_INCLUDED
